package indigo.mybatis.dao.criterion;

import static java.util.Objects.requireNonNull;

import java.util.Arrays;
import java.util.Collection;
import java.util.List;

import com.google.common.collect.ImmutableList;

public class Identifier extends Criterion {
	private static final long serialVersionUID = 4985850479289300781L;

	private final List<Object> ids;

	public Identifier(Object... ids) {
		this(Arrays.asList(ids));
	}

	public Identifier(Collection<?> ids) {
		this.ids = ImmutableList.copyOf(requireNonNull(ids, "ids cannot be null"));
	}

	public List<Object> getIds() {
		return ids;
	}

	@Override
	public String toString() {
		return String.format("Identifier {ids=%s}", ids.toString());
	}

	@Override
	public List<FlattenPart> flatten() {
		return ImmutableList.of(new IdentifierFlattenPart(this));
	}

	private static class IdentifierFlattenPart extends FlattenPart {
		public IdentifierFlattenPart(Identifier identifier) {
			super(Type.IDENTIFIER, identifier);
		}
	}
}
